import os

# 设置代理
os.environ["HF_ENDPOINT"] = "https://hf-mirror.com"

# 设置本地缓存目录
cache_dir = os.path.join('D:', os.path.sep, 'ModelSpace', 'Cache')
os.environ['HF_HOME'] = cache_dir

from transformers import pipeline
import scipy

# 创建Pipeline任务
nlp = pipeline("text-to-audio", model="suno/bark-small")

# 执行文本转音频任务
speech = nlp("Hello, my name is Suno. And, uh — and I like pizza. [laughs] But I also have other interests such as playing tic tac toe.", forward_params={"do_sample": True})

# 存储音频文件
scipy.io.wavfile.write("./output/01.bark.wav", rate=speech["sampling_rate"], data=speech["audio"].ravel())

